package com.gzz.orchid.common.webmvc.securityjwt;

import com.alibaba.fastjson2.JSON;
import com.gzz.orchid.common.webmvc.support.HttpResult;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.access.AccessDeniedException;
import org.springframework.security.web.access.AccessDeniedHandler;

import java.io.IOException;

/**
 * 鉴权失败处理器
 * 认证用户权限不足处理器
 *
 * @author higmd
 **/
@Slf4j
public class DelegateAccessDeniedHandler implements AccessDeniedHandler {
    @Override
    public void handle(HttpServletRequest request, HttpServletResponse response, AccessDeniedException e)
            throws IOException {

        response.setContentType("application/json;charset=UTF-8");
        response.getWriter()
                .println(JSON.toJSONString(HttpResult.failure().message("权限不足")));
    }

}
